package com.ezzd.service.impl;

import com.ezzd.EnmuInfo;
import com.ezzd.dao.GoodsDao;
import com.ezzd.pojo.TbGoods;
import com.ezzd.service.GoodsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description tb_goods
 * @author 被遗忘的湫
 * @date 2022-08-01
 */
@Service
@Transactional
public class GoodsServiceImpl implements GoodsService {

    @Resource
    private GoodsDao goodsDao;


    @Override
    public Object insert(TbGoods tbGoods) {

        // valid
        if (tbGoods == null) {
            return EnmuInfo.Fail;
        }

        goodsDao.insert(tbGoods);
        return EnmuInfo.Success;
    }


    @Override
    public Object delete(int id) {
        int ret = goodsDao.delete(id);
        return ret>0?EnmuInfo.Success:EnmuInfo.Fail;
    }


    @Override
    public Object update(TbGoods tbGoods) {
        int ret = goodsDao.update(tbGoods);
        return ret>0?EnmuInfo.Success:EnmuInfo.Fail;
    }


    @Override
    public TbGoods load(int id) {
        return goodsDao.load(id);
    }


    @Override
    public PageInfo<TbGoods> pageList(int pageNum, int pagesize) {

        PageHelper.startPage(pageNum, pagesize);
        List<TbGoods> pageList = goodsDao.pageList();

        PageInfo<TbGoods> pageInfo = new PageInfo<>(pageList);

        return pageInfo;
    }

    @Override
    public List<TbGoods> queryAll(){
        return goodsDao.queryAll();
    }

}
